/*
 * @Author       : mengqingxin
 * @Date         : 2020-10-25 17:58:51
 * @LastEditors  : mengqingxin
 * @LastEditTime : 2020-12-09 11:06:40
 */
// pages/home/home.js
import {queryArticle} from '../../api/article'
import {getEvaluateNum} from "../../api/claim.js"
const app = getApp()
Page({
    data: {
        checkboxSelect: '',
        items: [
            {value: 'true', name: '《用户协议》使用本小程序即代表同意用户协议'},
        ],
        evaluteNum: '',
        miniData: [],
        information: {},
        moduleList: [
            {
                name: '扫码安装',
                bgUrl: '/images/bg1.png',
                routeUrl: '/pages/scanCode/scanCode'
            },
            {
                name: '安装评价',
                bgUrl: '/images/bg3.png',
                routeUrl: '/pages/installationEvaluation/installationEvaluation'
            },
            {
                name: '我的工单',
                bgUrl: '/images/workOrderIcon.png',
                routeUrl: '/pages/logistics/logistics'
            },
            {
                name: '往尚驰寄件',
                bgUrl: '/images/bg2.png',
                routeUrl: '/pages/logisticsAdd/logisticsAdd'
            },

            // {
            //   name: '售后物流',
            //   bgUrl: '/images/bg2.png',
            //   routeUrl: '/pages/logistics/logistics'
            // }  ,

            // {
            //   name: '我的工单',
            //   bgUrl: '/images/workOrderIcon.png',
            //   routeUrl: '/pages/workOrder/workOrder'
            // },
            {
                name: '我的保质卡',
                bgUrl: '/images/bg4.png',
                routeUrl: '/pages/warrantyCard/warrantyCard'
            },
            {
                name: '我的报价单',
                bgUrl: '/images/workOrderIcon.png',
                routeUrl: '/pages/reportOrder/reportOrder'
            },
            {
                name: '联系客服',
                bgUrl: '/images/addwxPersonIcon.png',
                routeUrl: '/pages/addwxPerson/addwxPerson'
            },

        ]
    },
    queryBanner() {
        wx.showLoading({
            title: '加载中',
        })
        const formData = {
            category: 'carBanner',
            state: 'publish',
            pageNum: 1,
            pageSize: 3
        }
        queryArticle(formData).then(res => {
            let {data, success} = res
            if (success) {
                this.setData({
                    miniData: data.list
                })
            }
            this.queryInformation()
        }).catch(() => {
            this.queryInformation()
        })
    },
    queryInformation() {
        const formData = {
            category: 'carInformation',
            state: 'publish',
            pageNum: 1,
            pageSize: 1
        }
        queryArticle(formData).then(res => {
            let {data, success} = res
            if (success) {
                this.setData({
                    information: data.list[0] || {}
                })
            }
            wx.hideLoading()
        })
    },
    onLoad: function (options) {
        this.queryBanner();
        this.getEvaluateNum();
    },

    getEvaluateNum() {
        getEvaluateNum({type: '0'}).then(res => {
            let {data, success} = res;
            if (success) {
                this.setData({
                    evaluteNum: data
                })
            }
        })
    },

    onShareTimeline: function () {
        let json = {
            title: "尚驰海尔驻车空调"
        }
        return json
    },
    checkboxChange(e) {
    },
    onShow() {
        wx.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline']
        })
    },
    gotoPage: function (event) {
        if (event.currentTarget.dataset.id) {
            wx.navigateTo({
                url: `${event.currentTarget.dataset.url}?id=${event.currentTarget.dataset.id}`
            })
        } else {
            wx.navigateTo({
                url: event.currentTarget.dataset.url
            })
        }
    },
    searchButtonClick(e) {
        wx.navigateTo({
            url: `/pages/searchList/searchList?value=${e.detail}`
        })
    },
    gotoTab: function (event) {
        getApp().globalData.classType = event.currentTarget.dataset.classtype
        wx.switchTab({
            url: event.currentTarget.dataset.url
        })
    },
    gotos(e) {
      //console.log(e.currentTarget.dataset.url)
      if (!app.globalData.userId) {
          wx.showModal({
              title: '提示',
              content: '您还没有登录，确定登录吗？',
              success(res) {
                  if (res.confirm) {
                      wx.navigateTo({
                          url: '../login/login'
                      })
                  } else if (res.cancel) {
                      
                  }
              }
          })
      } else {
          wx.navigateTo({
              url: e.currentTarget.dataset.url
          })
      }
  }
})
